{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most examples work across multiple plotting backends, this example is also available for:\n",
    "\n",
    "* [Bokeh Directed Airline Routes](../bokeh/directed_airline_routes.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "import holoviews as hv\n",
    "from holoviews import opts\n",
    "\n",
    "from holoviews.element.graphs import layout_nodes\n",
    "from bokeh.sampledata.airport_routes import routes, airports\n",
    "\n",
    "hv.extension('matplotlib')\n",
    "\n",
    "hv.output(fig='svg')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Declare data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create dataset indexed by AirportID and with additional value dimension\n",
    "airports = hv.Dataset(airports, ['AirportID'], ['Name', 'IATA', 'City'])\n",
    "\n",
    "label = 'Alaska Airline Routes'\n",
    "\n",
    "# Select just Alaska Airline routes\n",
    "as_graph = hv.Graph((routes[routes.Airline=='AS'], airports), ['SourceID', \"DestinationID\"], 'Airline', label=label)\n",
    "\n",
    "as_graph = layout_nodes(as_graph, layout=nx.layout.fruchterman_reingold_layout)\n",
    "labels = hv.Labels(as_graph.nodes, ['x', 'y'], ['IATA', 'City'], label=label)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(as_graph * labels).opts(\n",
    "    opts.Graph(directed=True, node_size=8, padding=0.1, bgcolor='gray',\n",
    "               edge_color='white', edge_linewidth=1, arrowhead_length=0.01,\n",
    "               node_color='white', fig_size=300, xaxis=None, yaxis=None),\n",
    "    opts.Labels(xoffset=-0.04, yoffset=0.03, show_legend=False))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
